package main

import (
	"GORM_Demo04/part07/TestStruct"

	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

/**
一对多的添加数据，
	--关联添加数据需要操作的是领导表

*/

func main() {
	db, err := gorm.Open("mysql", "root:123456@tcp(192.168.11.189:3306)/lztest?charset=utf8&parseTime=True&loc=Local")

	if err != nil {
		panic(err)
	}
	defer db.Close()

	//创建两张表
	//db.CreateTable(&TestStruct.Leader{})
	//db.CreateTable(&TestStruct.Department{})
	//进行插入数据
	leader := TestStruct.Leader{

		LName: "张三",
		LAge:  20,
		Department: []TestStruct.Department{
			{
				DName: "第一商务部门",
				Desc:  "商务部门总经理",
			},
			{
				DName: "集团总部",
				Desc:  "集团总部副总",
			},
		},
	}

	db.Create(&leader)

}
